﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TransCode.Entitys;
using MongoDB.Driver;

namespace TransCode.Logic
{
    public class ServerLogic
    {
        MongoDatabase db = MongoDbHelper.DbInstance();

        public List<Server> ServerList()
        {
            List<Server> result = new List<Server>();

            return db.GetCollection<Server>("Server").FindAll().ToList();
        }

        public void Save(Server server)
        {
            db.GetCollection<Server>("Server").Save(server);
        }

        public void Delete(Server server)
        {
            if (server != null)
            {
                var query = new QueryDocument("_id", server.Id);
                db.GetCollection<Server>("Server").Remove(query);
            }
        }

        public Server GetServerByName(string name)
        {
            var query = new QueryDocument("ServerName", name);
            return db.GetCollection<Server>("Server").FindOne(query);
        }
    }
}
